package cc.vv.btpartyjob.partymanager.activity

import android.content.Intent
import android.view.View
import android.widget.TextView
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.delegate.ManagerBaseBinder
import cc.vv.btpartyjob.partymanager.delegate.RegisterAddressChooseActivityDelegate
import cc.vv.btpartyjob.partymanager.globle.IntentManageKey
import cc.vv.btpartyjob.partymanager.server.DataServer
import cc.vv.mvp.activity.BaseActivityMVP
import cc.vv.mvp.binder.BaseDataBinder
import com.chad.library.adapter.base.BaseQuickAdapter

/**
 * 报到地址选择（街道选择、社区选择）
 * Created by Chen.qi on 2018/10/27.
 */
class RegisterAddressChooseActivity : BaseActivityMVP<RegisterAddressChooseActivityDelegate>(), BaseQuickAdapter.OnItemClickListener {

    override fun initData() {
        val street = intent.getBooleanExtra(IntentManageKey.INTENT_KEY_ADDRESS_STREET, false)
        //街道
        val community = intent.getBooleanExtra(IntentManageKey.INTENT_KEY_ADDRESS_COMMUNITY, false)
        //社区
        val wangGe = intent.getBooleanExtra(IntentManageKey.INTENT_KEY_ADDRESS_WANG_GE, false)
        //网格
        when {
            street -> {
                viewDelegate?.setTopBarTitle("报到街道选择")
                viewDelegate?.setAdapterData(DataServer.getStreetData())
            }
            community -> {
                viewDelegate?.setTopBarTitle("报到社区选择")
                viewDelegate?.setAdapterData(DataServer.getCommunityAddressData())

            }
            wangGe -> viewDelegate?.setTopBarTitle("选择范围")
            else -> {
            }
        }
    }

    override fun bindEvenListener() {
        viewDelegate?.setTitleBackBtnOnClick(object : BaseTopBarView.EventInterface {
            //返回
            override fun leftOnClick() {
                finish()
            }

            override fun leftCloseClick() {}
            override fun rightOnClick() {
            }
        })

        viewDelegate?.bindOnItemClick(this)

    }

    override fun getDelegateClass(): Class<RegisterAddressChooseActivityDelegate> {
        return RegisterAddressChooseActivityDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return ManagerBaseBinder()
    }

    override fun onItemClick(adapter: BaseQuickAdapter<*, *>?, view: View?, position: Int) {
        val text = view?.findViewById<TextView>(R.id.tv_rac_addressChoose)?.text
        val intent = Intent()
        intent.putExtra(IntentManageKey.INTENT_KEY_ADDRESS_CHOOSE_RESULT_STR, text)
        setResult(200, intent)
        finish()
    }
}